2020-2021 Sunseeker Telemetry and Lighting System
eusci_b_i2c_ex1_slaveTxMultiple.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
68 //
69 //*****************************************************************************
70 //*****************************************************************************
71 //
72 //Set the address for slave module. This is a 7-bit address sent in the
73 //following format:
74 //[A6:A5:A4:A3:A2:A1:A0:RS]
75 //
76 //A zero in the "RS" position of the first byte means that the master
77 //transmits (sends) data to the selected slave, and a one in this position
78 //means that the master receives data from the slave.
79 //
80 //*****************************************************************************
81 #define SLAVE_ADDRESS 0x48
82 
83 uint8_t TXData = 0;
84 
85 void main(void)
86 {
87  WDT_A_hold(WDT_A_BASE);
88 
89  //Configure Pins for I2C (UCB0SCL, UCB0SDA)
90  //Set P2.5 and P2.6 as Module Function Input
91  GPIO_setAsPeripheralModuleFunctionInputPin(
92  GPIO_PORT_P2,
93  GPIO_PIN5 + GPIO_PIN6
94  );
95 
96  EUSCI_B_I2C_initSlaveParam param = {0};
97  param.slaveAddress = 0x48;
98  param.slaveAddressOffset = EUSCI_B_I2C_OWN_ADDRESS_OFFSET0;
99  param.slaveOwnAddressEnable = EUSCI_B_I2C_OWN_ADDRESS_ENABLE;
100  EUSCI_B_I2C_initSlave(EUSCI_B0_BASE, &param);
101 
102  EUSCI_B_I2C_enable(EUSCI_B0_BASE);
103 
104  EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE,
105  EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +
106  EUSCI_B_I2C_STOP_INTERRUPT
107  );
108 
109  EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE,
110  EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +
111  EUSCI_B_I2C_STOP_INTERRUPT
112  );
113 
114  // Enter LPM0 w/ interrupts
115  __bis_SR_register(CPUOFF + GIE);
116  __no_operation();
117 }
118 
119 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
120 #pragma vector=USCI_B0_VECTOR
121 __interrupt
122 #elif defined(__GNUC__)
123 __attribute__((interrupt(USCI_B0_VECTOR)))
124 #endif
125 void USCIB0_ISR(void)
126 {
127  switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
128  {
129  case USCI_NONE: // No interrupts break;
130  break;
131  case USCI_I2C_UCALIFG: // Arbitration lost
132  break;
133  case USCI_I2C_UCNACKIFG: // NAK received (master only)
134  break;
135  case USCI_I2C_UCSTTIFG: // START condition detected with own address (slave mode only)
136  break;
137  case USCI_I2C_UCSTPIFG: // STOP condition detected (master & slave mode)
138  TXData = 0;
139  break;
140  case USCI_I2C_UCRXIFG3: // RXIFG3
141  break;
142  case USCI_I2C_UCTXIFG3: // TXIFG3
143  break;
144  case USCI_I2C_UCRXIFG2: // RXIFG2
145  break;
146  case USCI_I2C_UCTXIFG2: // TXIFG2
147  break;
148  case USCI_I2C_UCRXIFG1: // RXIFG1
149  break;
150  case USCI_I2C_UCTXIFG1: // TXIFG1
151  break;
152  case USCI_I2C_UCRXIFG0: // RXIFG0
153  break;
154  case USCI_I2C_UCTXIFG0: // TXIFG0
155  EUSCI_B_I2C_slavePutData(EUSCI_B0_BASE,
156  TXData++);
157  break;
158  case USCI_I2C_UCBCNTIFG: // Byte count limit reached (UCBxTBCNT)
159  GPIO_toggleOutputOnPin(
160  GPIO_PORT_P1,
161  GPIO_PIN0
162  );
163  break;
164  case USCI_I2C_UCCLTOIFG: // Clock low timeout - clock held low too long
165  break;
166  case USCI_I2C_UCBIT9IFG: // Generated on 9th bit of a transmit (for debugging)
167  break;
168  default:
169  break;
170  }
171 }
void USCIB0_ISR(void)
void main(void)
MPU_initThreeSegmentsParam param
__no_operation()